<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="content-type" content="text/html; charset=UTF-8">
    <title>选课列表</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

</head>
<body>
    <h1 id="tips"></h1>
    <table border="1" id="table_content">
        <tr>
            <th>课程ID</th>
            <th>名称</th>
            <th>教师</th>
            <th>学分</th>
            <th>上课时间</th>
            <th>下课时间</th>
            <th>地点</th>
            <th>剩余</th>
            <th>总数</th>
            <th>选择</th>
        </tr>

    </table>
    <script>
        $.ajax({
            type:"POST",
            url:"Login",
            contentType: "application/json; charset=utf-8",
            data:JSON.stringify({account:"1",password:"2"}),
            success:function(data){
                console.log(data)
                if (data.status!="-1"){
                    $('#tips').prepend(`欢迎学生[${data.name}]来到永不死机选课系统。`)
                    getTableData()
                }else{
                    alert("未登录！")
                }
            },
            error:function(jqXHR){
                console.log("Error: "+jqXHR.status);
            }
        });
        function getTableData(){
            $.ajax({
                type:"POST",
                url:"getAllCourse",
                contentType: "application/json; charset=utf-8",
                data:JSON.stringify({account:"1",password:"2"}),
                success:function(data){
                    for (var item in data){
                        console.log(item);
                        $('#table_content').append(`

                        <tr>
                            <td>${data[item].course_id}</td>
                            <td>${data[item].course_name}</td>
                            <td>${data[item].teacher}</td>
                            <td>${data[item].point}</td>
                            <td>${data[item].timeon}</td>
                            <td>${data[item].timeend}</td>
                            <td>${data[item].location}</td>
                            <td>未知</td>
                            <td>${data[item].limited}</td>
                            <td><input type="checkbox" name="vehicle" value="Bike" /> </p></td>
                        </tr>
                     `)
                    }

                },
                error:function(jqXHR){
                    console.log("Error: "+jqXHR.status);
                }
            });
        }
        $('#submit').click(
            function () {
                var account = $('#account').val();
                var password = $('#password').val();
                $.ajax({
                    type:"POST",
                    url:"Login",
                    contentType: "application/json; charset=utf-8",
                    data:JSON.stringify({account:account,password:password}),
                    success:function(data){
                        console.log(data)
                        if (data.status!="-1"){
                            alert("登录成功！")
                        }else{
                            alert("登录失败！")
                        }
                    },
                    error:function(jqXHR){
                        console.log("Error: "+jqXHR.status);
                    }
                });
            }
        )

    </script>
</body>
</html>